<?php

class GetSLT {

	var $username;
	var $siteId;

	var $sslcert;
	var $sslkey;
	var $cainfo;
	
	function Request($_username, $_siteId) {
		$this->siteId = $_siteId;
		$this->username = $_username;		
		$url="https://ppsacredential.service.passport.net/pksecure/PPSACredentialPK.srf";		

		$data =         "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
		$data = $data . "   <soap:Header>";
		$data = $data . "     <WSSecurityHeader xmlns=\"http://schemas.microsoft.com/Passport/SoapServices/CredentialServiceAPI/V1\">";
		$data = $data . "         <version>eshHeader25</version>";
		$data = $data . "         <ppSoapHeader25><![CDATA[<s:ppSoapHeader xmlns:s=\"http://schemas.microsoft.com/Passport/SoapServices/SoapHeader\" version=\"1.0\"><s:lcid>1033</s:lcid><s:sitetoken><t:siteheader xmlns:t=\"http://schemas.microsoft.com/Passport/SiteToken\" id=\"" . $this->siteId . "\"/></s:sitetoken></s:ppSoapHeader>]]></ppSoapHeader25>";
		$data = $data . "     </WSSecurityHeader>";
		$data = $data . "   </soap:Header>";
		$data = $data . "   <soap:Body>";
		$data = $data . "      <GetSLT xmlns=\"http://schemas.microsoft.com/Passport/SoapServices/CredentialServiceAPI/V1\">";
		$data = $data . "         <PassIDIn>";
		$data = $data . "            <pit>PASSID_SIGNINNAME</pit>";
		$data = $data . "            <bstrID>" . $this->username . "</bstrID>";
		$data = $data . "         </PassIDIn>";
		$data = $data . "         <LoginSeconds>30</LoginSeconds>";
		$data = $data . "      </GetSLT>";
		$data = $data . "   </soap:Body>";
		$data = $data . "</soap:Envelope>";
		
		$tuCurl = curl_init();
		curl_setopt($tuCurl, CURLOPT_URL, $url);
		curl_setopt($tuCurl, CURLOPT_PORT , 443);
		curl_setopt($tuCurl, CURLOPT_VERBOSE, 1);
		curl_setopt($tuCurl, CURLOPT_HEADER, 1);
		curl_setopt($tuCurl, CURLOPT_SSLVERSION, 3);
		curl_setopt($tuCurl, CURLOPT_SSLCERT, $this->sslcert);
		curl_setopt($tuCurl, CURLOPT_SSLKEY, $this->sslkey);
		
		if ($this->cainfo != null) {			
			curl_setopt($tuCurl, CURLOPT_CAINFO, $this->cainfo);
		}
		
		curl_setopt($tuCurl, CURLOPT_POST, 1);
		curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data);
		curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($tuCurl, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml","SOAPAction: \"#GetSLT\"", "Content-length: ".strlen($data)));
		$tuData = curl_exec($tuCurl);		
		curl_close($tuCurl);		
		return $tuData;
	}
}

	$getSLT = new GetSLT();
	$getSLT->sslcert = getcwd() ."/private-cer.pem";
	$getSLT->sslkey = getcwd() ."/private.pem";
	$getSLT->cainfo = getcwd() . "/all.pem";
	
	$slt = $getSLT->Request("adam.j.bradley@adamjbradley.com","256296");	
	printf($slt);
?>

